<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程处理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
    <div class="Wrapper">
	    <div class="searchArea">
	    	<input name="isMore" id="isMore" type="text" style="display: none;" class="ui-textbox" value="${isMore}">
	        <form id="searchBar">
	            <div class="fieldset1 clearFix FBL5">
	                <div class="fieldBox">
						<div class="label">供应商名称</div>
		                <div class="field">
		                    <input name="splNm" id="splNm" type="text" class="ui-textbox" value="">
		                </div>
	                </div>
	                <span id="searchBtn" class="sq-button sq-button-round">查询</span>
	                <span id="cleanFormBtn" class="sq-button sq-button-round">清除</span>
	            </div>
	        </form>
	    </div>
	    <table >
	        <tbody>
	            <tr>
	                <td valign="top">
	                    <div class="sqPanel">
	                        <div class="sqPanel_body">
	                            <div id="ligergrid" class="sq-grid"></div>
	                             <div id="selecetedItems" class="textareaBox Hide" style="margin-top:10px; height:60px;"></div>
	                        </div>
	                    </div>
	                </td>
	            </tr>
	        </tbody>
	    </table>
	</div>

<script>
    var grid,
        grid_addPE;
    	combo_DATA=[];
    $(function () {
    	render_ligergrid("");
    	initForm();
    	initSearchEvent();
    	initClearLigerFormEvent();
    });
    
    
    frameElement.dialog.onOk = function () {
		save();
	}
	
	frameElement.dialog.onClear = function () {
		$("#cleanFormBtn").click();
        if (grid) {
        	reLoadGrid();
        } 
        change_combo_DATA("clear");
	}
	
	frameElement.dialog.onCancel = function () {
		frameElement.dialog.close();
	}

    
    //保存
    function save(){
    	if(!grid || grid.getSelecteds().length==0) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "error"});
            return false; //验证不通过，不执行以下代码
        }
        var data=[];
        for (var i = 0; i < combo_DATA.length; i++) {
            var combo_item=combo_DATA[i];
            for(key in combo_item){
                data.push(key);
            }
        };
        top.$.ligerDialog.SQconfirm("确定选择吗?",function (yes) {
            if (yes==false) return;
            if(frameElement && frameElement.dialog) {
                frameElement.dialog._DATA={usrIds: data}; //给父窗口的dialog传参
                frameElement.dialog.set("_usrs", combo_DATA); //给父窗口的dialog传参
                frameElement.dialog.close();
            }
        });
    }

    
    //清除按钮事件
    function initClearLigerFormEvent(){
    	$("#cleanFormBtn").click(function(event) {
            clearLigerForm("searchBar");
        });
    }
    
    //初始化查询事件
    function initSearchEvent(){
    	$("#searchBtn").click(function(event) {
    		reLoadGrid();
        });
    }
    
    //重新加载GRID
    function reLoadGrid(){
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
           grid.setParm(name,data[name]);
        };
       grid.reload();
    }
    
    //初始化查询Bar
    function initForm(){
    	$("#searchBar").ligerForm();
    }
    
    //渲染Grid
    function render_ligergrid (parms) {
        grid = $("#ligergrid").ligerGrid({
            url: "<%=path%>/product/splInfo/initList.do",
            parms: parms,
            method : 'get',
            fixedCellHeight: false,
            checkbox: true,
            // selectRowButtonOnly: true,
            // isSingleCheck: true,
            frozenCheckbox: false,
            allowHideColumn: false,
            columns: [{
                display: '名称',
                name: 'splNm',
                width: 220
            }, {
                display: '供应商属性',
                name: 'splAttrCd',
                width: 100,
                render: function (rowdata, rowindex, value){
            		if(StringUtils.isNotEmpty(value) && value==CustomerConstant.CST_TYPE_NP_CD){//1自然人 2法人
            			return "自然人";
            		}else if(StringUtils.isNotEmpty(value) && value==CustomerConstant.CST_TYPE_CORP_CD){
            			return "法人";
            		}else{
            			return "-";
            		}
                }
            }, {
                display: '营业执照号/证件号',
                name: 'bizLicNo',
                width: 120
            }],
            pageSize:10,
            width: '100%',
            isScroll: false,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            //usePagerOnLessPagesize: false,
            onSelectRow: function (rowdata, rowid, rowobj, j) {
                var obj={};
                obj[rowdata.id]=rowdata.splNm;
                if(grid.options.isSingleCheck) change_combo_DATA("clear");
                change_combo_DATA("add", obj);
            },
            onUnSelectRow: function (rowdata, rowid, rowobj) {
                var obj={};
                obj[rowdata.id]=rowdata.splNm;
                change_combo_DATA("delete", obj);
            },
            onAfterShowData: function() {
                SetIframe_height();
            }
        });
        //开启不同模式,默认模式为多选
        var isMore = $("#isMore").val();
        if(isMore == 0){
        	grid.options.isSingleCheck=true;
        }
    }
    
    
    function change_combo_DATA (method, obj) {
        if (method=="add") {
            for (var i = 0; i < combo_DATA.length; i++) {
                if(JSON.stringify(combo_DATA[i])==JSON.stringify(obj)) {
                    top.$.ligerDialog.SQalert({content: LogUtils.LOG_FLOW_PERSON_ALWAYS_HERE, SQ_type: "warning"});
                    return false;
                }
            };
            combo_DATA.push(obj);
        }
        if (method=="delete") arrDel(obj, combo_DATA);
        if (method=="clear") combo_DATA.length=0;
        view_combo_DATA ();
    }
    function view_combo_DATA () {
        if (combo_DATA.length==0) {
            $("#selecetedItems").addClass('Hide');
            return false;
        };
        var selecetedItems_h=[]
        for (var i = 0; i < combo_DATA.length; i++) {
            var selecetedItem=combo_DATA[i];
            for(key in selecetedItem){
                selecetedItems_h.push('<span>'+selecetedItem[key]+'</span>， ')
            }
        };
        $("#selecetedItems").removeClass('Hide').html(selecetedItems_h.join(''))
    }
    function arrDel (obj,arr) {
        for (var i = 0; i < arr.length; i++) {
            if(JSON.stringify(arr[i])==JSON.stringify(obj)) break;
        };
        arr.splice(i,1);
        return arr;
    }
    function setNanoScroller () {
        $(".nanoWrap .nano").nanoScroller({
            preventPageScrolling: true
        });
    }
    SET_popupIframeHeight();
</script>
</body>
</html>